#include <stdio.h>
#include <string.h>
#define NSIZE 8
void Bin2Text(const char *sIn, const char *sOut)
{
    FILE *fin = fopen(sIn, "r");
    FILE *fout = fopen(sOut, "w");
    char str[255 * 8];
    for (int r = 0; r < 255; r++)
        str[r] = '\0';
    int i = 0, j = 0, iTemp = 0, flag = 0;
    int ibina[NSIZE];
    char cRead[NSIZE];
    char cChar;
    for (int a = 0; a <= 255; a++)
        fscanf(fin, "%c", &str[a]);
    //for(int f=0 ; f<=255 ; f++)printf("%c",str[f]);
    while (flag <= 255)
    {
        //printf("%d",flag);
        for (int b = flag; b >= flag && b < flag + NSIZE; b++)
        {
            //printf("%d",b%8);
            cRead[b % 8] = str[b];
            //printf("%c",cRead[b%8]);
        }
        for (i = 0; i < NSIZE; i++)
        {
            ibina[i] = (cRead[i] - '0');
        }
        iTemp = 1;
        cChar = 0;
        for (j = 7; j >= 0; j--)
        {
            //printf("%c",ibina[j]);
            //printf("%d\n",cChar);
            cChar += ibina[j] * iTemp;
            iTemp *= 2;
        }
        printf("%c", cChar);
        fprintf(fout, "%c", cChar);
        flag = flag + 8;
    }
    fclose(fin);
    fclose(fout);
}
int main(int argc, char *argv[])
{
    Bin2Text(argv[1], argv[2]);
    printf("\nSuccessfully converted file!\n");
    return 0;
}
